import layout from "@/components/layout/layout";

const routers = [
  {
    path: "/",
    redirect: "/dashboard",
    component: layout,
    children: [
      /**
       * admin 路由视图
       */
      {
        path: "/company",
        name: "admin-company",
        meta: {
          name: "企业管理"
        },
        component: () => import("@/view/company/company"),
        roles: ["ROLE_ADMIN", "ROLE_OPERATION"]
      },
      {
        path: "/company/info",
        name: "admin-company-info",
        meta: {
          name: "企业数据管理"
        },
        component: () => import("@/view/company/companyTab"),
        roles: ["ROLE_ADMIN", "ROLE_OPERATION"]
      },
      {
        path: "/device",
        name: "admin-device",
        meta: {
          name: "设备管理"
        },
        component: () => import("@/view/device/device"),
        roles: ["ROLE_ADMIN", "ROLE_OPERATION"]
      },
      {
        path: "/device/info/:id",
        name: "admin-device-info",
        meta: {
          name: "设备管理"
        },
        component: () => import("@/view/device/tabs"),
        roles: ["ROLE_ADMIN", "ROLE_OPERATION"]
      },
      {
        path: "/alarm",
        name: "admin-alarm",
        meta: {
          name: "报警事件"
        },
        component: () => import("@/view/alarm/alarm"),
        roles: ["ROLE_ADMIN", "ROLE_OPERATION"]
      },
      {
        path: "/history",
        name: "admin-history",
        meta: {
          name: "历史数据"
        },
        component: () => import("@/view/history/history"),
        roles: ["ROLE_ADMIN", "ROLE_OPERATION"]
      },
      {
        path: "/offline",
        component: () => import("@/view/offline/offlineLayout"),
        roles: ["ROLE_ADMIN", "ROLE_OPERATION"],
        children: [
          {
            path: "/offline",
            name: "admin-offline",
            component: () => import("@/view/offline/offlineCount"),
            meta: {
              name: "离线统计"
            }
          },
          {
            path: "/offline/log",
            name: "admin-settingoffline",
            meta: {
              name: "离线记录"
            },
            component: () => import("@/view/offline/offlineLog")
          }
        ]
      },
      {
        path: "/setting",
        meta: {
          name: "设置"
        },
        redirect: "/setting/city",
        component: () => import("@/view/setting/layout"),
        roles: ["ROLE_ADMIN", "ROLE_OPERATION"],
        children: [
          {
            path: "/setting/city",
            name: "admin-settingcity",
            meta: {
              name: "城市管理"
            },
            component: () => import("@/view/setting/city/city")
          },
          {
            path: "/setting/article",
            name: "admin-settingarticle",
            meta: {
              name: "App文章管理"
            },
            component: () => import("@/view/setting/article/article")
          },
          {
            path: "/setting/user",
            name: "admin-settinguser",
            meta: {
              name: "用户管理"
            },
            component: () => import("@/view/setting/UserManage/UserManage")
          },

          {
            path: "/setting/region",
            name: "admin-settingRegion",
            meta: {
              name: "地域管理"
            },
            component: () => import("@/view/setting/RegionManage")
          },
          {
            path: "/setting/trade",
            name: "admin-setting-trade",
            meta: {
              name: "行业管理"
            },
            component: () => import("@/view/setting/TradeManage")
          },
          {
            path: "/setting/type",
            name: "admin-setting-type",
            meta: {
              name: "设备类型管理"
            },
            component: () => import("@/view/setting/DeviceType")
          },
          {
            path: "/setting/gateway/type",
            name: "admin-setting-gateway-type",
            meta: {
              name: "网关类型"
            },
            component: () => import("@/view/setting/Gateway/GatewayType")
          },
          {
            path: "/setting/gateway/list",
            name: "admin-setting-gateway-list",
            meta: {
              name: "网关列表"
            },
            component: () => import("@/view/setting/Gateway/GatewayList")
          },
          {
            path: "/setting/build-report",
            name: "admin-setting-build-report",
            meta: {
              name: "报告生成"
            },
            component: () => import("@/view/BuildReport")
          },
          {
            path: "/setting/company-channel",
            name: "admin-setting-company-channel",
            meta: {
              name: "企业渠道管理"
            },
            component: () => import("@/view/setting/company-channel")
          }
        ]
      },
      {
        path: "/video",
        component: () => import("@/view/video/layout"),
        roles: ["ROLE_ADMIN", "ROLE_DEMO", "ROLE_OPERATION"],
        redirect: "/video/device",
        children: [
          {
            path: "/video/device",
            name: "admin-videoDevice",
            meta: {
              name: "视频设备管理"
            },
            component: () => import("@/view/video/device/device")
          },
          {
            path: "/video/device/detail/:id",
            name: "admin-videoDeviceInfo",
            meta: {
              name: "热成像监控设备详情"
            },
            component: () => import("@/view/video/device/deviceDetail")
          },
          {
            path: "/video/device/distribute/:id",
            name: "admin-videoDistribute",
            meta: {
              name: "热成像监控设备热力分布"
            },
            component: () => import("@/view/video/device/videoDistribute")
          },
          {
            path: "/video/device/player/:id",
            name: "admin-videoPlayer",
            meta: {
              name: "热成像监控设备视频播放"
            },
            component: () => import("@/view/video/device/videoPlayer")
          },
          {
            path: "/video/alarm",
            name: "admin-videoAlarm",
            meta: {
              name: "热成像监控设备报警事件"
            },
            component: () => import("@/view/video/alarm/alarm")
          },
          {
            path: "/video/params",
            name: "admin-videoParams",
            meta: {
              name: "热成像监控设备参数设置"
            },
            component: () => import("@/view/video/paramsSetting/paramsSetting")
          }
        ]
      },
      {
        path: "/temperature",
        component: () => import("@/view/temAndHumidity/layout"),
        roles: ["ROLE_ADMIN", "ROLE_OPERATION"],
        redirect: "/temperature/device",
        children: [
          {
            path: "/temperature/device",
            name: "admin-temperatureDevice",
            component: () => import("@/view/temAndHumidity/device/device"),
            meta: {
              name: "温湿度设备管理"
            }
          },
          {
            path: "/temperature/device/:id",
            name: "admin-temperatureDevice-detail",
            component: () =>
              import("@/view/temAndHumidity/device/components/deviceDetail"),
            meta: {
              name: "温湿度设备详情"
            }
          },
          {
            path: "/temperature/alarm",
            name: "admin-temperatureAlarm",
            component: () => import("@/view/temAndHumidity/alarm/alarm"),
            meta: {
              name: "温湿度设备报警事件"
            }
          },
          {
            path: "/temperature/params",
            name: "admin-temperatureParams",
            component: () => import("@/view/temAndHumidity/params/params"),
            meta: {
              name: "温湿度设备参数设置"
            }
          }
        ]
      },

      {
        path: "/iot",
        component: () => import("@/view/iot/Layout"),
        roles: ["ROLE_ADMIN", "ROLE_OPERATION"],
        children: [
          {
            path: "/iot",
            name: "admin-iot",
            component: () => import("@/view/iot/IotList"),
            meta: {
              name: "iot产品列表"
            }
          },
          {
            path: "/iot/device",
            name: "admin-iot-device",
            meta: {
              name: "iot设备管理"
            },
            component: () => import("@/view/iot/IotDevice")
          },
          {
            path: "/iot/device/:id/:nodeType",
            name: "admin-iot-device-detail",
            meta: {
              name: "iot设备详情"
            },
            component: () => import("@/view/iot/components/deviceDetail")
          },
          {
            path: "/iot/alert",
            name: "admin-iot-alert",
            meta: {
              name: "iot报警事件"
            },
            component: () => import("@/view/iot/IotAlert")
          },
          {
            path: "/iot/history",
            name: "admin-iot-history",
            meta: {
              name: "iot历史数据"
            },
            component: () => import("@/view/iot/IotHistory")
          }
        ]
      },

      /**
       * 用户路由视图
       */
      {
        path: "/user/main",
        name: "userMain",
        component: () => import("@/pages/main/main"),
        roles: [
          "ROLE_ADMIN",
          "ROLE_USER",
          "ROLE_PLATFORM",
          "ROLE_GOV",
          "ROLE_OPERATION",
          "ROLE_DEMO"
        ],
        meta: {
          name: "首页"
        }
      },
      {
        path: "/user/device/:id?",
        name: "userDevice",
        component: () => import("@/pages/UserDevice/index"),
        roles: [
          "ROLE_ADMIN",
          "ROLE_USER",
          "ROLE_PLATFORM",
          "ROLE_GOV",
          "ROLE_OPERATION",
          "ROLE_DEMO"
        ],
        meta: {
          name: "设备管理"
        }
      },
      {
        path: "/user/errorthing/:id?",
        name: "userErrorthing",
        component: () => import("@/pages/errThing/errThing"),
        roles: [
          "ROLE_ADMIN",
          "ROLE_USER",
          "ROLE_PLATFORM",
          "ROLE_GOV",
          "ROLE_OPERATION",
          "ROLE_DEMO"
        ],
        meta: {
          name: "报警事件"
        }
      },
      {
        path: "/user/history",
        name: "userHistory",
        component: () => import("@/pages/history/history"),
        roles: [
          "ROLE_ADMIN",
          "ROLE_USER",
          "ROLE_PLATFORM",
          "ROLE_GOV",
          "ROLE_OPERATION",
          "ROLE_DEMO"
        ],
        meta: {
          name: "历史数据"
        }
      },
      {
        path: "/user/report",
        name: "userReport",
        component: () => import("@/pages/report/report"),
        roles: [
          "ROLE_ADMIN",
          "ROLE_USER",
          "ROLE_PLATFORM",
          "ROLE_GOV",
          "ROLE_OPERATION",
          "ROLE_DEMO"
        ],
        meta: {
          name: "诊断报告"
        }
      },
      {
        path: "/analysis",
        name: "Analysis",
        redirect: "/analysis/report",
        component: () => import("@/pages/Analysis/Layout"),
        roles: [
          "ROLE_ADMIN",
          "ROLE_USER",
          "ROLE_PLATFORM",
          "ROLE_GOV",
          "ROLE_OPERATION",
          "ROLE_DEMO"
        ],
        children: [
          {
            path: "/analysis/report",
            name: "AnalysisReport",
            component: () => import("@/pages/Analysis/ReportForms/Layout"),
            meta: {
              name: "统计报表"
            }
          },
          /**实时数据报表+实时详情 */
          {
            path: "/analysis/ontime",
            name: "AnalysisOntime",
            component: () => import("@/pages/Analysis/OnTime/Layout"),
            meta: {
              name: "实时数据报表"
            }
          },
          {
            path: "/analysis/ontime/load/:id/:name",
            name: "AnalysisOntimeLoad",
            component: () => import("@/pages/AnalysisDetail/Dayly/Load"),
            meta: {
              name: "实时负荷详情"
            }
          },
          {
            path: "/analysis/ontime/power/:id/:name",
            name: "AnalysisOntimePower",
            component: () => import("@/pages/AnalysisDetail/Dayly/Power"),
            meta: {
              name: "实时电量详情"
            }
          },
          {
            path: "/analysis/ontime/voltage/:id/:name",
            name: "AnalysisOntimeVoltage",
            component: () => import("@/pages/AnalysisDetail/Dayly/Voltage"),
            meta: {
              name: "实时电压详情"
            }
          },
          {
            path: "/analysis/ontime/current/:id/:name",
            name: "AnalysisOntimeCurrent",
            component: () => import("@/pages/AnalysisDetail/Dayly/Current"),
            meta: {
              name: "实时电流详情"
            }
          },
          {
            path: "/analysis/ontime/powerfactor/:id/:name",
            name: "AnalysisOntimePowerFactor",
            component: () => import("@/pages/AnalysisDetail/Dayly/PowerFactor"),
            meta: {
              name: "实时功率因数详情"
            }
          },

          /**日数据报表+日详情 */
          {
            path: "/analysis/dayly",
            name: "AnalysisDayly",
            component: () => import("@/pages/Analysis/Dayly/Layout"),
            meta: {
              name: "日数据报表"
            }
          },
          {
            path: "/analysis/dayly/load/:id/:name/:time",
            name: "AnalysisDaylyLoad",
            component: () => import("@/pages/AnalysisDetail/Dayly/Load"),
            meta: {
              name: "日负荷详情"
            }
          },
          {
            path: "/analysis/dayly/power/:id/:name/:time",
            name: "AnalysisDaylyPower",
            component: () => import("@/pages/AnalysisDetail/Dayly/Power"),
            meta: {
              name: "日电量详情"
            }
          },
          {
            path: "/analysis/dayly/voltage/:id/:name/:time",
            name: "AnalysisDaylyVoltage",
            component: () => import("@/pages/AnalysisDetail/Dayly/Voltage"),
            meta: {
              name: "日电压详情"
            }
          },
          {
            path: "/analysis/dayly/current/:id/:name/:time",
            name: "AnalysisDaylyCurrent",
            component: () => import("@/pages/AnalysisDetail/Dayly/Current"),
            meta: {
              name: "日电流详情"
            }
          },
          {
            path: "/analysis/dayly/powerfactor/:id/:name/:time",
            name: "AnalysisDaylyPowerFactor",
            component: () => import("@/pages/AnalysisDetail/Dayly/PowerFactor"),
            meta: {
              name: "日功率因数详情"
            }
          },
          /** 周数据报表*/
          {
            path: "/analysis/weekly",
            name: "AnalysisWeekly",
            component: () => import("@/pages/Analysis/Weekly/Layout"),
            meta: {
              name: "周数据报表"
            }
          },
          {
            path: "/analysis/weekly/load/:id/:name/:time",
            name: "AnalysisWeeklyLoad",
            component: () => import("@/pages/AnalysisDetail/Weekly/Load"),
            meta: {
              name: "周负荷详情"
            }
          },
          {
            path: "/analysis/weekly/power/:id/:name/:time",
            name: "AnalysisWeeklyPower",
            component: () => import("@/pages/AnalysisDetail/Weekly/Power"),
            meta: {
              name: "周电量详情"
            }
          },
          {
            path: "/analysis/weekly/voltage/:id/:name/:time",
            name: "AnalysisWeeklyVoltage",
            component: () => import("@/pages/AnalysisDetail/Weekly/Voltage"),
            meta: {
              name: "周电压详情"
            }
          },
          {
            path: "/analysis/weekly/current/:id/:name/:time",
            name: "AnalysisWeeklyCurrent",
            component: () => import("@/pages/AnalysisDetail/Weekly/Current"),
            meta: {
              name: "周电流详情"
            }
          },
          {
            path: "/analysis/weekly/powerfactor/:id/:name/:time",
            name: "AnalysisWeeklyPowerFactor",
            component: () =>
              import("@/pages/AnalysisDetail/Weekly/PowerFactor"),
            meta: {
              name: "周功率因数详情"
            }
          },

          /**
           * 月数据报表
           */
          {
            path: "/analysis/monthly",
            name: "AnalysisMonthly",
            component: () => import("@/pages/Analysis/Monthly/Layout"),
            meta: {
              name: "月数据报表"
            }
          },
          {
            path: "/analysis/monthly/load/:id/:name/:time",
            name: "AnalysisMonthlyLoad",
            component: () => import("@/pages/AnalysisDetail/Monthly/Load"),
            meta: {
              name: "月负荷详情"
            }
          },
          {
            path: "/analysis/monthly/power/:id/:name/:time",
            name: "AnalysisMonthlyPower",
            component: () => import("@/pages/AnalysisDetail/Monthly/Power"),
            meta: {
              name: "月电量详情"
            }
          },
          {
            path: "/analysis/monthly/powerfactor/:id/:name/:time",
            name: "AnalysisMonthlyPowerFactor",
            component: () =>
              import("@/pages/AnalysisDetail/Monthly/PowerFactor"),
            meta: {
              name: "日功率因数详情"
            }
          }
        ]
      },
      {
        path: "/user/video",
        name: "userVideo",
        component: () => import("@/pages/uvideo/video"),
        meta: {
          name: "热成像监控"
        },
        roles: [
          "ROLE_ADMIN",
          "ROLE_USER",
          "ROLE_PLATFORM",
          "ROLE_GOV",
          "ROLE_OPERATION",
          "ROLE_DEMO"
        ]
      },
      {
        path: "/user/video/detail/:id",
        name: "userVideoDetail",
        component: () => import("@/pages/uvideo/components/deviceDetail"),
        meta: {
          name: "数据详情"
        },
        roles: [
          "ROLE_ADMIN",
          "ROLE_USER",
          "ROLE_PLATFORM",
          "ROLE_GOV",
          "ROLE_OPERATION",
          "ROLE_DEMO"
        ]
      },
      {
        path: "/user/video/device/distribute/:id",
        name: "userVideoDistribute",
        component: () => import("@/pages/uvideo/components/videoDistribute"),
        meta: {
          name: "热力分布"
        },
        roles: [
          "ROLE_ADMIN",
          "ROLE_USER",
          "ROLE_PLATFORM",
          "ROLE_GOV",
          "ROLE_OPERATION",
          "ROLE_DEMO"
        ]
      },
      {
        path: "/user/video/device/player/:id",
        name: "userVideoPlayer",
        component: () => import("@/pages/uvideo/components/videoPlayer"),
        meta: {
          name: "视频图像"
        },
        roles: [
          "ROLE_ADMIN",
          "ROLE_USER",
          "ROLE_PLATFORM",
          "ROLE_GOV",
          "ROLE_OPERATION",
          "ROLE_DEMO"
        ]
      },
      {
        path: "/user/temperature",
        name: "userTemperature",
        component: () => import("@/pages/tempHumidity"),
        meta: {
          name: "温湿度"
        },
        roles: [
          "ROLE_ADMIN",
          "ROLE_USER",
          "ROLE_PLATFORM",
          "ROLE_GOV",
          "ROLE_OPERATION",
          "ROLE_DEMO"
        ]
      },
      {
        path: "/user/temperature/:id",
        name: "userTemperatureDetail",
        component: () => import("@/pages/tempHumidity/deviceDetail"),
        meta: {
          name: "温湿度设备详情"
        },
        roles: [
          "ROLE_ADMIN",
          "ROLE_USER",
          "ROLE_PLATFORM",
          "ROLE_GOV",
          "ROLE_OPERATION",
          "ROLE_DEMO"
        ]
      }
    ]
  },

  {
    path: "/dashboard",
    name: "Dashboard",
    component: () => import("@/view/Dashboard/index"),
    meta: {
      name: "用电安全物联网平台"
    },
    roles: [
      "ROLE_ADMIN",
      "ROLE_USER",
      "ROLE_PLATFORM",
      "ROLE_GOV",
      "ROLE_DEMO",
      "ROLE_OPERATION",
      "ROLE_DEMO"
    ]
  },
  {
    path: "/datacenter",
    name: "dataCenter",
    // component: () => import('@/view/DataCenter/DataCenter'),
    component: () => import("@/view/dataCenter2"),
    meta: {
      name: "数据中心"
    },
    roles: [
      "ROLE_ADMIN",
      "ROLE_USER",
      "ROLE_PLATFORM",
      "ROLE_GOV",
      "ROLE_OPERATION",
      "ROLE_DEMO"
    ]
  },
  /**代理商 */
  {
    path: "/agent",
    name: "Agent",
    component: () => import("@/pages/AgentHome"),
    meta: {
      name: "用电安全物联网平台"
    },
    roles: ["ROLE_PLATFORM"]
  },
  {
    path: "/manage/gallery",
    name: "PowerPicture",
    meta: {
      name: "配电图"
    },
    component: () => import("@/view/power-picture/index"),
    roles: [
      "ROLE_ADMIN",
      "ROLE_USER",
      "ROLE_PLATFORM",
      "ROLE_GOV",
      "ROLE_DEMO",
      "ROLE_OPERATION",
      "ROLE_DEMO"
    ]
  },
  {
    path: "/",
    name: "ProvinceAndCityMapName",
    component: () => import("@/view/DataCenter/DataCenter"),
    meta: {
      name: "用电安全物联网平台"
    },
    roles: ["ROLE_PROVINCE"]
  },
  {
    path: "*",
    name: "404",
    roles: [
      "ROLE_PROVINCE",
      "ROLE_ADMIN",
      "ROLE_DEMO",
      "ROLE_OPERATION",
      "ROLE_USER",
      "ROLE_PLATFORM",
      "ROLE_GOV"
    ],
    component: () => import("@/components/errPage/404")
  }
];

export default type => {
  const result = routers.filter(t => {
    if (t.children) {
      t.children = t.children.filter(t1 => {
        if (t1.roles && t1.roles.indexOf(type) > -1) {
          return t1;
        }
      });
      return t.children.length === 0 ? false : t.children;
    }
    if (!t.children && t.roles && t.roles.indexOf(type) > -1) {
      return t;
    }
  });

  if (type === "ROLE_PLATFORM") {
    result[0].redirect = "/agent";
  } else if (type === "ROLE_USER") {
    result[0].redirect = "/datacenter";
  } else if (type === "ROLE_OPERATION") {
    result[0].redirect = "/company";
  }

  return result;
};
